package com.css.zfzx.sjcj.modules.statistics.fxEconomicLossLevelMap.controller;

import com.alibaba.fastjson.JSONObject;
import com.css.bpm.platform.base.response.RestResponse;
import com.css.bpm.platform.utils.PlatformPageUtils;
import com.css.zfzx.sjcj.common.utils.ServerUtil;
import com.css.zfzx.sjcj.modules.pojo.QueryVo;
import com.css.zfzx.sjcj.modules.statistics.fxEconomicLossLevelMap.service.FxEconomicLossLevelMapService;
import com.css.zfzx.sjcj.modules.statistics.fxqhHddc100.service.FxqhHddc100Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/pc/fxEconomicLossLevelMap")
public class FxEconomicLossLevelMapController {
    @Autowired
    FxEconomicLossLevelMapService service;
    ///pc/fxEconomicLossLevelMap/findData/{identify}
    @GetMapping("/findData/{identify}")
    public RestResponse findData(@PathVariable int identify, QueryVo queryVo, HttpServletRequest req) {
        RestResponse response = null;
        String userId = ServerUtil.getUserId(req);
        try{
            int curPage = Integer.valueOf(req.getParameter(PlatformPageUtils.CUR_PAGE));
            int pageSize = Integer.valueOf(req.getParameter(PlatformPageUtils.PAGE_SIZE));
            String sort= req.getParameter("sort");
            String order= req.getParameter("order");
            JSONObject list = service.find(queryVo,userId,curPage,pageSize,identify,sort,order);
            response = RestResponse.succeed(list);
        }catch (Exception e){
            String errorMessage = "查询失败!";
            response = RestResponse.fail(errorMessage);
        }
        return response;
    }

    @GetMapping("/export/{identify}")
    public void export(@PathVariable int identify, HttpServletRequest req, HttpServletResponse resp) {
        String userId = ServerUtil.getUserId(req);
        service.export(userId,resp,identify);
    }

    /***
     * 系统自动质检
     * @param identify
     * @return
     */
    @PostMapping("/dataQualityCheck/{identify}")
    public RestResponse dataQualityCheck(@PathVariable("identify")int identify,
                                         @RequestBody QueryVo queryVo) {
        RestResponse responseRest = null;
        JSONObject jsonObject = new JSONObject();
        try{
            service.dataQualityCheck(queryVo,identify);
            jsonObject.put("message", "质检成功！");
            responseRest = RestResponse.succeed(jsonObject);
        }catch (Exception e){
            String errorMessage = "质检失败!";
            responseRest = RestResponse.fail(errorMessage);
        }
        return responseRest;
    }
}
